package com.javacode2018.lesson001.demo8;

import com.javacode2018.lesson001.demo5.IocUtil;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @Author: hongsir
 * @Date: 2024/10/10 - 10 - 10 - 15:18
 * @Description: com.javacode2018.lesson001.demo8
 * @Version: 1.0
 */
public class PrimaryTest {
    @Test
    public void normalBean(){
        String beanXml = "classpath:/com/javacode2018/lesson001/demo8/normalBean.xml";
        ClassPathXmlApplicationContext context = IocUtil.context(beanXml);
        //下面我们通过spring容器的T getBean(Class<T> requiredType)方法获取容器中对应的bean
        NormalBean.IService service = context.getBean(NormalBean.IService.class); //@1
        System.out.println(service);
    }

    @Test
    public void setterBean(){
        String beanXml = "classpath:/com/javacode2018/lesson001/demo8/setterBean.xml";
        ClassPathXmlApplicationContext context = IocUtil.context(beanXml);
    }

    @Test
    public void primaryBean(){
        String beanXml = "classpath:/com/javacode2018/lesson001/demo8/primaryBean.xml";
        ClassPathXmlApplicationContext context = IocUtil.context(beanXml);
        PrimaryBean.IService service = context.getBean(PrimaryBean.IService.class); //@1
        System.out.println(service);
        PrimaryBean primaryBean = context.getBean(PrimaryBean.class); //@2
        System.out.println(primaryBean);
    }
}
